# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=a2ps
pkgver=4.14
pkgrel=9
pkgdesc="a2ps is an Any to PostScript filter"
url="https://www.gnu.org/software/a2ps/"
arch="all"
license="GPL-3.0"
depends="ghostscript imagemagick perl"
makedepends="gperf autoconf automake libtool"
subpackages="$pkgname-dev $pkgname-doc"
source="https://ftp.gnu.org/gnu/a2ps/a2ps-$pkgver.tar.gz
	$pkgname-4.13c-fnmatch-replacement.patch
	$pkgname-4.13c-emacs.patch
	$pkgname-4.13-manpage-chmod.patch
	$pkgname-$pkgver-check-mempcpy.patch
	$pkgname-$pkgver-fix-stpcpy-proto.patch
	fix-redeclarations.patch
	a2ps-automake-1.12.patch
	automake.patch
	CVE-2001-1593.patch
	CVE-2014-0466.patch
	"

prepare() {
	default_prepare

	update_config_sub
	update_config_guess

	sed -i -e 's/__mempcpy/mempcpy/g' lib/strftime.c src/regex.c
	rm -f aclocal.m4 ./*/aclocal.m4
	libtoolize --force --copy
	aclocal -I m4 && automake --add-missing && autoreconf -I m4
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc/a2ps \
		--includedir=/usr/include \
		--disable-nls
	make
}

package() {
	make -j1 DESTDIR="$pkgdir" install
	sed -i "s:^countdictstack: \0:" "$pkgdir"/usr/bin/psset
}

sha512sums="fd6ac8ab47d789114c283e8ca508f7f56feabd1a189f4ac772cad9e6be7e3791e210892cfffd04ad1d39efe4b15386b2e61bf4cd56b70ed581c0554f36bfe06f  a2ps-4.14.tar.gz
5509ae1277ff1f1f487fb106ed6673eb67fa7d1531a35bfa087f78a0bdb4dc0bf38c69b7fab95161a19406fc1acaef09b22b8a05ef603c6d43a8d7a8c3077b56  a2ps-4.13c-fnmatch-replacement.patch
0ef1a215ecb757e249c4d4bdf9a789419c6cd433f7e330783fef13a0158c57c5c5e6a22526d8abcca0919bdb1dc08337869fdd3f0fe192284ca087eafad322a3  a2ps-4.13c-emacs.patch
f3dc2698ee989928b3179b65b01bf12d828f4428bd860f6f1a3811daaa9d6256b353c2acb5cd4bf392dd89b040f8e9c15420ab4373f3d54b8b60652aaf23f864  a2ps-4.13-manpage-chmod.patch
6835f5e9205cb549da52c4a3c13aad601c9e9d294f0f35ebe4d8cc6f8bd8b5f6fe77b857f8c92f552a43c02eb6de812021c078ce597c319bde176f0e91cd167b  a2ps-4.14-check-mempcpy.patch
605385c355b15f2f8142b4a05390ce131d3f2b7a8d56bf37b70457db64c0ce458778daf05ef015c9059482483907a629f12d210bcaa91cc007af4f708b66b765  a2ps-4.14-fix-stpcpy-proto.patch
08382d49982190779f3070e06af773c0dd730e8f1a81310a537c149a438954e5c4b360c72a908fb50b1fb95fcf4b556c28ffd90932bae81140cab30b3419f364  fix-redeclarations.patch
422dba4b43fb14d68263361dd917a866a9ff033d4a5f60faf668385b80093f7f3f6025de149810f9287790acc07ed5f5feb15c7b23ff083ab74eb21c22bf0f05  a2ps-automake-1.12.patch
4336ad6b40ecfd16ac01304a4d27b7715e5c19ef3777b57f0ea152fa1a57db476605c330b5c0091dfbf95705e4345806c8393e6c3f3e89d528bd94cc91a9beb9  automake.patch
22b9e23d74a914a3332615b911c655cf5e63ce445073e2cd7faa353c16b3e9c813cc4f3b20db68795f09da8b5a8952effe4727e6d1a429699ad66487bd2cab32  CVE-2001-1593.patch
1816c8c98c8902801c5376ed86821b60d67c18fe9f5534936e3fa9ffaae01f1b1f5b4cf84fa176ba30ee7350737fffa3c2e4b60cf03cb9e64bc93487a6448bb1  CVE-2014-0466.patch"
